package com.daqsoft.util;

import com.daqsoft.dto.ExtTreeNode;
import com.daqsoft.dto.IViewCascader;
import com.daqsoft.dto.IViewTree;

import java.util.ArrayList;
import java.util.List;

/**
 * iView工具类
 * @author 周麟东 on 14:40
 */
public enum  IViewUtil {
    INS;

    public List<IViewCascader> treeToCascader(List<IViewTree> tree){
        List<IViewCascader> cascaders = new ArrayList<>();
        for (IViewTree pNode : tree) {
            IViewCascader father = new IViewCascader();
            father.setLabel(pNode.getTitle());
            father.setValue(pNode.getId());
            List<IViewCascader> children = new ArrayList<>();
            for (IViewTree node : pNode.getChildren()) {
                IViewCascader child = new IViewCascader();
                child.setLabel(node.getTitle());
                child.setValue(node.getId());
                children.add(child);
            }
            father.setChildren(children);
            cascaders.add(father);
        }
        return cascaders;
    }
    public List<IViewCascader> moduleTreeToCascader(List<ExtTreeNode> tree){
        List<IViewCascader> cascaders = new ArrayList<>();
        for (ExtTreeNode pNode : tree) {
            IViewCascader father = new IViewCascader();
            father.setLabel(pNode.getText());
            father.setValue(pNode.getId()+"");
            List<IViewCascader> children = new ArrayList<>();
            for (ExtTreeNode node : pNode.getChildren()) {
                IViewCascader child = new IViewCascader();
                child.setLabel(node.getText());
                child.setValue(node.getId()+"");
                children.add(child);
            }
            father.setChildren(children);
            cascaders.add(father);
        }
        return cascaders;
    }
}
